<?php

/**
 * ArrayAccess是对象像数组一样操作
 */
class Article implements ArrayAccess
{
	public $title;
	public $author;
	public $category;
	
	public function __construct($title, $author, $category) {
		$this->title = $title;
		$this->author = $author;
		$this->category = $category;
	}
	
	public function offsetExists ($offset) {
		return array_key_exists($offset, get_object_vars($this));
	}

	
	public function offsetGet ($offset) {
		if ($this->offsetExists($offset)) {
			return $this->$offset;
		}
	}

	
	public function offsetSet ($offset, $value) {
		if ($this->offsetExists($offset)) {
			$this->$offset = $value;
		}
	}

	
	public function offsetUnset ($offset) {
		if ($this->offsetExists($offset)) {
			unset($this->$offset);
		}
	}
}

$article = new Article('s', 'sugang', 'time');
echo '<pre>';
var_dump($article);

$article['title'] = 'title';

$article['ss'] = 123;

unset($article['author']);

var_dump($article);